#-*- coding:utf-8 -*-
import os
from HTMLParser import HTMLParser

htm_file_path = "/var/www/html/htm_file/"
htm_full_file = htm_file_path + os.listdir(htm_file_path)[0]

def TakeFileContent(filename):
    FileContent = open(filename).read()
    return FileContent

if os.path.isfile(htm_full_file):
    FileContent = TakeFileContent(htm_full_file)
else:
    print "出错误了。"

l = ['pre', 'hgroup', 'figure', 'p', 'h2', 'h3', 'h1', 'h6', 'h7', 'h4', 'h5', 'tfoot', 'header', 'video', 'table', 'label', 'select', 'canvas', 'span', 'sub', 'img', 'area', 'tbody', 'menu', 'section', 'tr', 'aside', 'blockquote>', 'li', 'source', 'nav', 'details', 'th', 'sup', 'u', 'td', 'thead', 'body', 'map', 'dl', 'fieldset', 'form', 'hr', 'big', 'dd', 'figcaption', 'ol', 'br', 'article', 'dt', 'strong', 'embed', 'a', 'b', 'textarea', 'footer', 'i', 'button', 'q', 'ul', 'del', 'dialog', 'small', 'div', 'audio', 'tt']

class MyHTMLParser(HTMLParser):
    def __init__(self):
        HTMLParser.__init__(self)
        self.values = []
    def handle_starttag(self, tag, attrs):
        if tag in l:
            if len(attrs) == 0: pass
            else:
                for (variable, value)  in attrs:
                    if variable == "class" or variable == 'id':
                        self.values.append(value)


hp = MyHTMLParser()
hp.feed(FileContent)
hp.close()

HtmDom = hp.values
HtmDomList = []
for x in HtmDom:
        for y in x.split(' '):
            HtmDomList.append(y)
HtmDomList = list(set(HtmDomList))
while '' in HtmDomList:
    HtmDomList.remove('')
HtmDomList = HtmDomList + l

